﻿function validLogin()
{
    var valueUsername = $("#txtUserID").attr("value");
    var valuePassword = $("#txtPassword").attr("value");
    var radioUnitLogin = $("#radioUnitLogin").attr("checked");
    if(valueUsername.length<=0)
    {
        $("#txtUserID").attr("class","failbox");
        alert("请输入用户名/身份证号!");
        return false;
    }
    if ((radioUnitLogin == "checked" || radioUnitLogin == true) ) 
    {
            if (valuePassword.length <= 0)
             {
                $("#txtPassword").attr("class", "failbox");
                alert("请输入用户密码!");
                return false;
              }
    }
    else
    {
       return  cidValidate(valueUsername);
    }
}

function cidValidate(sId) {
    var iSum = 0;
    var info = "";
    var ErrorMsg = "身份证不正确.";
    if (!/^\d{17}(\d|x)$/i.test(sId)) {
        alert(ErrorMsg);
        return false;
    }
    sId = sId.replace(/x$/i, "a");
    if (aCity[parseInt(sId.substr(0, 2))] == null) {
        ErrorMsg += "错误:非法地区";
        alert(ErrorMsg);
        return false;
    }
    for (var i = 17; i >= 0; i--) iSum += (Math.pow(2, i) % 11) * parseInt(sId.charAt(17 - i), 11)
    if (iSum % 11 != 1) {
        ErrorMsg += "错误:非法证号";
        alert(ErrorMsg);
        return false;
    }
    return true;
}
function changeClass(o)
{
    if(o.className !="textbox")
        o.className ="textbox";
}
